package com.cssw.fyzb.busi.api.acct;


import com.cssw.fyzb.core.exception.BizException;
import com.cssw.fyzb.busi.service.acct.OutAcctService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: yangyiqun
 * @Date: 2020/7/11 16:25
 */
@Function(description = "保存支付宝信息", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true),
        @Parameter(name = "realName", type = Type.String, description = "姓名", required = true),
        @Parameter(name = "aliNo", type = Type.String, description = "支付宝账号", required = true),
        @Parameter(name = "receQrCode", type = Type.String, description = "收款码", required = true)
})
@Component
public class SaveAliPay implements Action {
    private static final Logger logger = LoggerFactory.getLogger(SaveAliPay.class);

    @Autowired
    private OutAcctService outAcctService;

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        String name = request.getString("realName");
        String aliNo = request.getString("aliNo");
        String receQrCode = request.getString("receQrCode");
        try {
            outAcctService.saveAli(userId, name, aliNo, receQrCode);
        }
        catch(Exception e){
            if (e instanceof BizException){
                BizException be = (BizException) e;
                return Response.fail(be.getErrMsg(), be.getErrCode());
            }
            logger.error("", e);
            return Response.fail("保存支付宝信息失败");
        }
        finally {
        }
        return Response.success();
    }
}
